<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
#use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('admin_roles')) return;
        Schema::create('admin_roles', function (Blueprint $table) {
            $table->id()->unsigned()->autoIncrement();
            $table->string('name')->default('')->index()->comment('角色名称');
            $table->boolean('is_super')->default(0)->index()->comment('是否超级管理员：1是 0否');
            $table->string('desc')->default('')->comment('描述');
            $table->text('menu_ids')->comment('权限ID集合，存储结构为json数据，内容为admin_menus表ID集合');
            $table->text('menu_texts')->comment('权限ID集合，存储结构为json数据，内容为admin_menus表ID集合');
            $table->boolean('is_delete')->default(0)->comment('是否删除：1是 0否');
            $table->dateTime('created_at')->default(\DB::raw('CURRENT_TIMESTAMP'));
            $table->timestamp('updated_at')->default(\DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
        });
        DB::statement("ALTER TABLE `admin_roles` COMMENT '后台角色'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (!is_production()) Schema::dropIfExists('admin_roles');
    }
};
